package com.myspring.web.view.json;

import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * 参考资料：
 * https://spring.io/blog/2013/05/11/content-negotiation-using-spring-mvc
 * https://spring.io/blog/2013/06/03/content-negotiation-using-views
 *
 * @RestController = @Controller + ResponseBody返回json或者String
 * @author : zenghua
 * @version : v0.1 JsonController.java
 * @since : 2018/5/3 10:00
 */
@RestController
@RequestMapping("/json")
public class JsonController {

	@RequestMapping
	public String init() {
		return "json/json";
	}

	@RequestMapping("/content.json")
	public JsonContent content() {

		return this.buildContent();
	}

	public JsonContent buildContent() {
		JsonContent jsonContent = new JsonContent();
		jsonContent.setContent("json");
		Map<String, String> map = new HashMap<>();
		map.put("negotiation", "contentNegotiationManager");
		jsonContent.setMap(map);
		return jsonContent;
	}

	public static void main(String[] args) {
		String s = StringUtils.join("a", "b");
		System.out.println(s);
	}
}
